package com.wlr.blog.article.controller;

import com.wlr.blog.util.common.dto.Result;
import com.wlr.blog.web.common.dto.UserDetails;
import com.wlr.blog.web.common.entity.User;
import com.wlr.blog.web.common.service.UserService;
import com.wlr.blog.web.common.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lrwang
 * @version 1.0
 * @date 2022/12/7 12:27
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/register")
    public Result<?> register(@RequestBody UserVo user) {
        boolean register = userService.register(user);
        return register ? Result.success() : Result.error("注册失败");
    }

    @PostMapping("/login")
    public Result<?> login(@RequestBody User user) {
        UserDetails userDetails = userService.login(user);
        return userDetails != null ? Result.success("登陆成功", userDetails) : Result.error("登陆失败");
    }
}
